package com.han.jdbc.spring.jpa.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.han.jdbc.spring.jpa.domain.CustomerCopy;

/**
* @author hanpeng
* @version 创建时间：2020年8月16日 上午10:05:24
* @ClassName 类名称
* @Description 类描述
* JpaRepository<操作的实体类型, 实体类主键属性的类型> 如CustomerCopy 中主键为@Column(name = "cust_id")
	                                                              private Long custId; // 客户的主键 类型为Long
	           1,JpaRepository 封装了基本的crud 操作
* JpaSpecificationExecutor<操作的实体类型> 
*              1,封装了复杂查询 如分页
*/
public interface CustomerDaoCopy extends JpaRepository<CustomerCopy, Long>,JpaSpecificationExecutor<CustomerCopy>{
	@Query(value = "from CustomerCopy where custName = ?1",name="xxxxx",countName="cus")
	public CustomerCopy findJpql(String custName);
	
	
	/**
	 * @param id 客户id 
	 * @param name 客户名称 
	 * @return
	 * SELECT  * FROM  cst_customer  WHERE cust_name="dsf" AND cust_id=1 原生sql
	 * (Long id, String name);
	 *       1          2
	 */
	@Query(value = "FROM CustomerCopy where custName = ?2 and custId = ?1",name="findCustNameAndIdsas")
	public CustomerCopy findCustNameAndId(Long id, String name);
	
	
	@Query(value = " update CustomerCopy set custName = ?2 where custId = ?1 ")
    @Modifying
    public void updateCustomer(long custId,String custName);
	
	/**
	 * @param custName
	 * @return
	 * nativeQuery = true 表示使用sql查询
	 */
	@Query(value="select * from cst_customer where cust_name like ?1",nativeQuery = true)
    public List<Object [] > findSql(String custName);
    
    /**
     * @param custName
     * @return
     * 通过方法命名来确定查询 
     * 如findByCustName===>FROM CustomerCopy where custName =
     * findBy+属性名====》FROM 实体类 WHERE  custName =
     * findBy + 属性名 + “查询方式”   + “多条件的连接符（and|or）”  + 属性名 + “查询方式”
     * 
     * 2.findBy  + 属性名称 + “查询方式（Like | isnull）”
     * 1.findBy  + 属性名称 （根据属性名称进行完成匹配的查询=）
     */
    public CustomerCopy findByCustName(String custName);
    public List<CustomerCopy> findByCustNameLike(String custName);
    public CustomerCopy findByCustNameLikeAndCustIndustry(String custName,String custIndustry);
}
